from rest_framework import serializers
from user import models
import re


def check_phone(value):
#     手机号是否满足正则
    if re.match(r'^1[3-9]\d{9}$', value):
            return value
    else:
        raise serializers.ValidationError('手机号格式不正确')

class Userr(serializers.ModelSerializer):
    class Meta:
        model=models.User
        field="__all__"
        extra_kwargs={
            'phone': {'required': True,
                         "validators": [check_phone],
                         "error_messages": {
                             "required": "phone is required",
                         }
                         }
        }